#include "Wiinner.h"

/** @brief Contructeur de la classe scene
 *
 *  construit la scene
 *
 */
Scene::Scene(){
    device = createDevice(EDT_OPENGL,dimension2d<irr::u32>(800,600),32,false,true,false,0);
    driver = device->getVideoDriver ();
    sceneManager = device->getSceneManager ();

    device->getCursorControl ()-> setVisible (false);

    SKeyMap keyMap[5];
    keyMap[0].Action = irr::EKA_MOVE_FORWARD;
    keyMap[0].KeyCode = irr::KEY_KEY_Z;
    keyMap[1].Action = irr::EKA_MOVE_BACKWARD;
    keyMap[1].KeyCode = irr::KEY_KEY_S;
    keyMap[2].Action = irr::EKA_STRAFE_LEFT;
    keyMap[2].KeyCode = irr::KEY_KEY_Q;
    keyMap[3].Action = irr::EKA_STRAFE_RIGHT;
    keyMap[3].KeyCode = irr::KEY_KEY_D;
    keyMap[4].Action = irr::EKA_JUMP_UP;
    keyMap[4].KeyCode = irr::KEY_SPACE;
    camera = sceneManager->addCameraSceneNodeFPS (0,100.0f,0.5f, -1, keyMap, 5, false, 0.4);
    camera->setPosition(vector3df(10.0, 50.0, -50.0));
    room = sceneManager->getMesh("room.3ds");
    Nroom = sceneManager->addMeshSceneNode(room->getMesh(0));
    Nroom->setMaterialFlag(EMF_LIGHTING, true);

    sceneManager->getMeshManipulator()->makePlanarTextureMapping(room->getMesh(0), 0.004f);
    Nroom->setMaterialTexture(0,driver->getTexture("rockwall.bmp") );
    sceneManager->setAmbientLight(SColorf(1.0, 1.0, 1.0,0.0));

}

/** @brief Destructeur */
Scene::~Scene(){
    device->drop();
}

/** @brief fonction qui affiche e rendu de la scene */
void Scene::drawScene(){
    device->run();
    driver->beginScene(true, true, irr::video::SColor(0,255,255,255));
    sceneManager->drawAll ();
    driver->endScene ();
}

/** @brief fonction qui affiche le rendu de la scene
*   @param startPosition
*   indique la position du debut de la ligne
*   @param endPosition
*   indique la position de la fin de la ligne
*   @param color
*   indique la couleur de la ligne
*/
void Scene::drawLine(irr::core::vector3df startPosition, irr::core::vector3df endPosition, irr::video::SColor color){
    new nodeLine(sceneManager->getRootSceneNode(), sceneManager, startPosition, endPosition, color, -1);
}
